classdef BetweenClassDistance < Algorithm & Metric
    %BETWEENCLASSDISTANCE Summary of this class goes here
    %   Detailed explanation goes here
    
    properties
    end
    
    methods
        function [ this ] = BetweenClassDistance( name )
            if nargin == 0
                this.setName('bet_class_dist');
            end
            if nargin >= 1
                this.setName(name);
            end
        end
    end
    
    methods
        function [ z_result ] = apply( this, X, Y )
            z_result = this.calc(X, Y);
        end
    end
    
    methods ( Static = true )
        function [ z_result ] = calc( X, Y )
            nLabel = size(Y, 2);
            z_result = zeros(1, nLabel);
            for iLabel = 1:nLabel
                z_result(iLabel) = calcBetweenClassDistance(X, Y(:, iLabel));
            end
        end
    end
    
end

function [ result ] = calcBetweenClassDistance( X, Y )

z_id_1 = Y == 1;
z_id_2 = Y ~= 1;

nObs1 = nnz(z_id_1);
nObs2 = nnz(z_id_2);

if nObs1 == 0 || nObs2 == 0
    error('');
end

X1 = X(z_id_1, :);
X2 = X(z_id_2, :);
X1_mean = mean(X1, 1);
X2_mean = mean(X2, 1);

result = norm(X1_mean - X2_mean);

end
